Serving R with Ark

Lionel Henry

Where is the R in Positron?

  • Posit’s new IDE Positron is multilingual

  • Focus broadened to Python 🐍🐍🐍
    Where does this leave us with R?

Positron and Ark

  • Positron extensible and interoperable
    via independent backends

  • Most of the R support is
    implemented in Ark

30 months of work

  • Jonathan McPherson and Kevin Ushey started the project in early 2022

  • Davis Vaughan, Romain François, Daniel Falbel, Julia Silge, Jenny Bryan, and I joined in 2023

What’s in the Ark?

  1. 🤔 An LSP server
  2. 🫨 A DAP server
  3. 🤯 A Jupyter kernel

Goal: For R support to be independent of Positron

What’s in the Ark?

  • Trend of language servers in last decade

  • Interoperability via a standard protocol

  • Great for diversity!
    Same tooling shared by users of Emacs, nvim, VS Code, …

(1) Language Server Protocol

Language Server Protocol

LSP deals with suggestions, diagnostics, formatting, …

  • Knows about your source code and its dependencies
    Gets updates when user types
  • Parses code (tree-sitter), indexes it, analyses it
  • Provides code assistance

LSP: Completion

LSP: SignatureHelp

LSP: Hover

(2) Debug Adapter Protocol

Debug Adapter Protocol

DAP deals with breakpoints and stepping through code

  • Injects browser() calls at break points (TODO)
  • Manages source references and location
  • Creates virtual documents for external functions
  • Inspects local variables while stepping

DAP

(3) Jupyter kernel

A missing piece?

  • Dev-oriented editors get by with a LSP and DAP

  • Data-oriented editors need interactive execution

  • Assistance => LSP
    Debugging => DAP
    Execution => ???

Two approaches

  • Implement IDE API for the language (e.g. RStudio)
    • Specific to each interpreter
    • Ad hoc communication with frontend

  • Communicate with raw text (e.g. ESS)
    • Hard to match inputs to outputs
    • Makes background interaction difficult

Can we do better?

Jupyter

A native kernel for R

  • IRkernel is an R package
    Easy to install from CRAN
  • Ark implements the IDE API
    Manages R externally
  • Native behaviour like in RStudio or the terminal

sys.calls()

Three-in-one

Fully reusable infrastructure for R support

  • Assistance => LSP

  • Debugging => DAP

  • Execution => Jupyter

The whole is greater than the sum of its parts

But we plan standalone releases

Multilingualism in Positron

Demo

Stepping through base R at R and C++ levels

Towards shared R support

  • Already usable in all existing Jupyter apps
  • Still need to build support in other editors

Towards modern R tooling

Exciting opportunities for future development

  • Smarter code analysis and diagnostics
  • Annotation of package code with declare()

Conclusion

  • Ark aims for R to remain a first-class citizen
    in the evolving IDE landscape
    • More collaboration between IDE maintainers
    • Long-term sustainability of R tooling